<template>
  <div style="min-width: 829px">
    <div v-if="$route.path == '/projectAdmin/evaluate'">
      <div class="vs-search-box">
        <el-form ref="form" :inline="true" :model="paging" label-width="110px">
          <el-form-item label="日期">
            <el-date-picker
              value-format="yyyy-MM-dd"
              v-model="paging.date"
              style="width: 250px"
              type="date"
              placeholder="请选择"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="手机号">
            <el-input style="width: 200px" v-model="paging.phone"></el-input>
          </el-form-item>
          <el-form-item label="订单编号">
            <el-input
              style="width: 200px"
              v-model="paging.out_trade_no"
            ></el-input>
          </el-form-item>
          <el-form-item label="顾客姓名">
            <el-input style="width: 200px" v-model="paging.name"></el-input>
          </el-form-item>
          <el-form-item label="" class="vs-right-btns">
            <el-button @click="reset">重置</el-button>
            <el-button @click="handleCurrentChange(1)" type="primary"
              >查询</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <div class="vs-table-box">
        <!-- <div class="operation-box clear-float">
          <el-button @click="setRow()" style="margin-left: auto" type="primary"
            >新增</el-button
          >
        </div> -->
        <el-table
          v-loading="loading"
          :data="tableData"
          header-row-class-name="has-gutter-table"
          style="width: 100%"
        >
          <el-table-column label="订单编号" min-width="150">
            <template slot-scope="scope">
              <span v-if="scope.row.ordersProject.orders">{{
                scope.row.ordersProject.orders.out_trade_no
              }}</span>
            </template>
          </el-table-column>
          <el-table-column label="顾客姓名">
            <template slot-scope="scope">
              <span v-if="scope.row.user">{{ scope.row.user.username }}</span>
            </template>
          </el-table-column>
          <el-table-column label="手机号">
            <template slot-scope="scope">
              <span v-if="scope.row.user">{{ scope.row.user.phone }}</span>
            </template>
          </el-table-column>
          <el-table-column label="会员等级">
            <template slot-scope="scope">
              <p v-if="scope.row.user">
                <span v-if="scope.row.user.vip != null">{{
                  scope.row.user.vip.title
                }}</span>
                <span v-else>散客</span>
              </p>
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="评价时间">
          </el-table-column>
          <el-table-column prop="project_score" label="评价星级">
          </el-table-column>
          <el-table-column prop="content" label="评价内容"> </el-table-column>
          <el-table-column label="评价标签">
            <template slot-scope="scope" v-if="scope.row.typeList">
              <span
                style="margin: 0 3px"
                v-for="(ele, index) in scope.row.typeList"
                :key="index"
                >{{ ele.title }}</span
              >
            </template>
          </el-table-column>
          <el-table-column fixed="right" width="200" label="操作">
            <template slot-scope="scope">
              <span @click="setRow(1, scope.row)" class="tab-table-text"
                >查看</span
              >
              <span
                @click="setRow(2, scope.row)"
                class="tab-table-text"
                v-if="scope.row.status == 0"
                >通过</span
              >
              <span
                @click="setRow(3, scope.row)"
                class="tab-table-text"
                v-if="scope.row.status == 1"
                >隐藏</span
              >
              <span
                @click="setRow(4, scope.row)"
                class="tab-table-text"
                v-if="scope.row.is_top == 0"
                >置顶</span
              >
              <span
                @click="setRow(5, scope.row)"
                class="tab-table-text"
                v-if="scope.row.is_top == 1"
                >取消置顶</span
              >
              <span
                @click="setRow(6, scope.row)"
                class="tab-table-text"
                v-if="!scope.row.reply_time"
                >回复</span
              >
              <span
                @click="setRow(7, scope.row)"
                class="tab-table-text"
                v-if="!scope.row.reply_time"
                >快捷回复</span
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="vs-paging-box">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="paging.page"
            :page-size="paging.limit"
            layout="sizes,prev, pager, next, jumper"
            :total="paging.total"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <router-view></router-view>
    <el-dialog title="快捷回复" :visible.sync="dialogVisible" width="30%">
      <div class="groupList">
        <div class="list">
          <p v-for="(ele, index) in resultList" :key="index">
            <span>{{ ele.content }}</span>
            <span @click="reply(ele.content)">一键回复</span>
          </p>
        </div>
      </div>
      <span slot="footer" class="dialog-footer"></span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      resultList: [],
      dialogVisible: false,
      options: [
        {
          value: "正大店",
          label: "正大店",
        },
      ],
      recordList: [],
      loading: false,
      paging: {
        page: 1,
        total: 0,
        limit: 10,
        out_trade_no: "",
        date: "",
        name: "",
        store_id: "",
        phone: "", //姓名
      },
      tableData: [],
      from: {
        id: "",
        reply_content: "",
      },
      labelList: [],
    };
  },
  async created() {
    await this.getEvaluate();
    await this.GetList();
    await this.projectGetQuick();
  },
  filters: {
    KindType(val) {
      switch (val) {
        case "1":
          val = "好评";
          break;
        case "2":
          val = "服务";
          break;
        case "3":
          val = "技术";
          break;
        case "4":
          val = "价格";
          break;
      }
      return val;
    },
  },
  methods: {
    // 获取标签列表
    async getEvaluate() {
      let { code, data } = await this.$Http.getEvaluate({ is_all: 1 });
      if (code) {
        this.labelList = data;
      }
    },
    // 回复
    async reply(ele) {
      this.from.reply_content = ele;
      let { code } = await this.$Http.projectReplyComment(this.from);
      if (code) {
        this.$message.success("回复成功");
        this.dialogVisible = false;
        this.GetList();
      }
    },
    //   获取项目评价列表
    async projectGetQuick() {
      let { code, data } = await this.$Http.projectGetQuick();
      if (code) {
        this.resultList = data;
        console.log(this.resultList, "888888888888888");
      }
    },
    async GetList() {
      this.loading = true;
      let { code, data } = await this.$Http.projectGetComment(this.paging);
      this.loading = false;
      if (code) {
        // let arr = ["", "好评", "服务", "技术", "质量", "价格"];
        if (data.data.length) {
          data.data.forEach((ele) => {
            ele.evaluate_label_id = String(ele.evaluate_label_id).split(",");
            let typeList = [];
            ele.evaluate_label_id.forEach((item) => {
              this.labelList.forEach((list) => {
                if (item == list.id) {
                  typeList.push(list);
                }
              });
              ele.typeList = typeList;
            });
          });
        }
        this.tableData = data.data;
        this.paging.total = data.total;
      }
    },
    handleSizeChange(val) {
      this.paging.limit = val;
      this.GetList();
    },
    handleCurrentChange(val) {
      this.paging.page = val;
      this.GetList();
    },
    async setRow(type, row) {
      if (type == 1) {
        //查看
        this.utils.goUrl(
          `/projectAdmin/evaluate/AddEvaluate?id=${row.id}&type=1`
        );
      } else if (type == 2) {
        //通过
        let { code, data } = await this.$Http.projectApplyComment({
          id: row.id,
          status: 1,
        });
        if (code) {
          this.$message.success("您已通过此评论");
          this.GetList();
        }
      } else if (type == 3) {
        //隐藏
        let { code, data } = await this.$Http.projectApplyComment({
          id: row.id,
          status: 0,
        });
        if (code) {
          this.$message.success("您已隐藏此评论");
          this.GetList();
        }
      } else if (type == 4) {
        //置顶
        let { code, data } = await this.$Http.projectTopComment({
          id: row.id,
          is_top: 1,
        });
        if (code) {
          this.$message.success("您已置顶此评论");
          this.GetList();
        }
      } else if (type == 5) {
        //取消置顶
        let { code, data } = await this.$Http.projectTopComment({
          id: row.id,
          is_top: 0,
        });
        if (code) {
          this.$message.success("您已取消置顶此评论");
          this.GetList();
        }
      } else if (type == 6) {
        //回复
        this.utils.goUrl(
          `/projectAdmin/evaluate/AddEvaluate?id=${row.id}&type=2`
        );
      } else if (type == 7) {
        //快捷回复
        this.dialogVisible = true;
        this.from.id = row.id;
      }
      return;
      this.utils.goUrl("/projectAdmin/evaluate/AddEvaluate");
    },
    reset() {
      //重置
      this.paging = this.$options.data().paging;
      this.GetList();
    },
  },
};
</script>

<style lang="scss" scoped>
.image-thumbnail {
  width: 130px;
  height: 130px;
}
::v-deep {
  .el-dialog__body {
    padding: 0 20px;
  }
}
.groupList {
  .list {
    p {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin: 15px 0;
    }
    span:nth-child(2) {
      cursor: pointer;
    }
  }
}
</style>